package com.dbs.config;

import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.data.redis.connection.RedisConnectionFactory;
import org.springframework.data.redis.connection.jedis.JedisConnectionFactory;
import org.springframework.data.redis.core.RedisTemplate;
import org.springframework.data.redis.serializer.*;

import com.dbs.interfaces.group.entity.User;

@Configuration
public class RedisConfig {
	@Bean
	JedisConnectionFactory jedisConnectionFactory() {
		//return new JedisConnectionFactory();设置了密码就不能返回默认的类
		JedisConnectionFactory jedisConnectionFactory = new JedisConnectionFactory(); 
		jedisConnectionFactory.setPassword("jinmuyan");; 
		return jedisConnectionFactory; 
	}

	@Bean
	public  RedisTemplate<String, User> redisTemplate(RedisConnectionFactory factory) {
		RedisTemplate<String, User> template = new RedisTemplate<String, User>();
		//template.setConnectionFactory(jedisConnectionFactory());
		template.setConnectionFactory(factory);
		template.setKeySerializer(new StringRedisSerializer());
		template.setValueSerializer(new RedisObjectSerializer());
		return template;
	}
}
